<!-- TreeMenu.vue -->
<template>
  <div>
    <div v-for="item in menuArr" :key="item.id">
      <!-- 特殊情况 -->
      <el-menu-item
        :index="item.code"
        @click="switchView(item.url, item.code, null)"
        v-if="item.code == 'menu00060009'"
      >
        <i :class="item.icon"></i>
        <span>{{ item.title }}</span>
      </el-menu-item>
      <!-- 常规情况 -->
      <el-menu-item
        :index="item.code"
        @click="switchView(item.url, item.code, null)"
        v-else-if="item.children == null || item.children.length == 0"
      >
        <i :class="item.icon"></i>
        <span>{{ item.title }}</span>
      </el-menu-item>
      <!-- 递归情况 -->
      <el-submenu :index="item.code" v-else>
        <template slot="title">
          <i :class="item.icon"></i>
          <span>{{ item.title }}</span>
        </template>
        <!-- 递归调用组件，将下一层级的数据传入 -->
        <TreeMenu :menuArr="item.children" :switchView="switchView"></TreeMenu>
      </el-submenu>

    </div>
  </div>
</template>

<script>
export default {
  name: "TreeMenu", //组件名
  props: {
    menuArr: {
      type: Array,
      default: () => [],
    },
    switchView: {
      type: Function,
      default: null,
    },
  },
};
</script>
